package com.training.android.customlist;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomListBaseAdapter extends BaseAdapter {
	private Activity activity;
	private ArrayList<Character> data;
	private static LayoutInflater inflater = null;

	public CustomListBaseAdapter(Activity a, ArrayList<Character> d) {
		activity = a;
		data = d;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		if (convertView == null)
			vi = inflater.inflate(R.layout.adapter_listview, null);
		ImageView image = (ImageView) vi.findViewById(R.id.list_image);
		TextView name = (TextView) vi.findViewById(R.id.nameTextView);
		Character c = new Character();
		c = data.get(position);
		name.setText(c.getName());
		image.setImageDrawable(c.getImage());
		return vi;
	}

}
